<template>
	<el-dialog :close-on-click-modal="false" title="编辑单词" v-model="visible" :width="700" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
			<el-row>
				<el-col :span="24">
					<el-form-item label="标题" prop="title">
						{{ form.original }}
					</el-form-item>
					<el-form-item label="音标" prop="phonetic">
						<el-input v-model="form.phonetic" placeholder="请输入音标"></el-input>
					</el-form-item>
					<el-form-item label="意思" prop="translation">
						<el-input v-model="form.translation" placeholder="请输入单词意思"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>

<script>
export default {
	name: "word-edit",
	emits: ['success', 'closed'],
	components: {},
	props: {},
	data() {
		return {
			course: null,
			visible: false,
			isSaveing: false,
			index1: false,
			index2: false,
			form: this.getDefaultRuleForm(),
			rules: {
				phonetic: [
					{required: false, message: '请输入音标'},
				]
			},
			dicts: [],
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(data,index1,index2) {
			this.index1 = index1
			this.index2 = index2
			this.visible = true;
			this.setData(data)
		},
		//表单提交方法
		async submit() {
			if (!await this.$refs.dialogForm.validate().catch(() => {
				return false
			})) {
				return false
			}
			let _data = this.form
			this.$emit('success', _data, this.index1, this.index2)
			this.visible = false;
		},
		//表单注入数据
		async setData(row) {
			this.loading = true
			let _form = {
				original: row.original,
				phonetic: row.phonetic,
				translation: row.translation,
			}

			this.form = _form
		},
		getDefaultRuleForm() {
			return {
				phonetic: '',
				original: '',
				translation: '',
			}
		},
	}
}
</script>

<style>
</style>
